<?php

namespace XWAM\Addon\POrgUser\Controller;

/**
 * 用户控制器
 * <br />中转站
 *
 * @since 1.0 <2014-6-13> sutroon Added.
 */
class UserController extends \XWAM\Controller\AppbaseController {

    public function user_list($type_name = 'ADMIN') {
        $urls = array(
            'ADMIN' => AddonU('UserAdmin/user_list'),
            'SERVICES' => AddonU('UserServices/user_list'),
            'CUSTOMER' => AddonU('UserCustomer/user_list'),
        );
        if (array_key_exists($type_name, $urls)) {
            redirect($urls[$type_name]);
        } else {
            exit('不支持的用户类型[' . $type_name . ']!');
        }
    }

    function profile_edit() {
        $uid=$this->user_login_data['id'];
        $type_name = AddonD('User')->where(array('id' => $uid))->getField('type_name');
        $urls = array(
            'ADMIN' => AddonU('UserAdmin/profile_edit'),
            'SERVICES' => AddonU('UserServices/profile_edit'),
            'CUSTOMER' => AddonU('UserCustomer/profile_edit'),
        );
        if (array_key_exists($type_name, $urls)) {
            redirect($urls[$type_name]);
        } else {
            exit('不支持的用户类型[' . $type_name . ']!');
        }
    }

    function change_online_status($id, $status) {
        $this->ajaxReturn(AddonD('User')->change_online_status($id, $status));
    }

    public function user_role($id) {
        $this->assign('data', AddonD('User')->find($id));
        $this->display();
    }

    /**
     * 保存管理员角色
     * @since 1.0 <2015-8-4> SoChishun Added.
     */
    public function user_role_save() {
        $id = I('id');
        $role_id = I('role_id');
        if (!$id || !$role_id) {
            $this->act_error(false, '参数有误');
        }
        $result = M('tuser_member')->where(array('id' => $id))->setField('role_id', $role_id);
        $this->act_close_dialog($result, '保存%!');
    }

}
